<?php
/*
*文章接口类
*/
class articleAppClass extends appBase{
	/*业务技能*/
	public function clientTalk(){
		if(!$this->power("clientTalk","see")){
			$json['warn'] = "您没有查看业务技能的权限";
		}else{
			$json = $this->home(array("type" => "内部管理","classify" => "业务技能"));
		}
		//返回
		return $json;
	}
	/*管理制度*/
	public function adSystem(){
		if(!$this->power("adSystem","see")){
			$json['warn'] = "您没有查看管理制度的权限";
		}else{
			$json = $this->home(array("type" => "内部管理","classify" => "管理制度"));
		}
		//返回
		return $json;
	}
	/*开发文档*/
	public function api(){
		if(!$this->power("api","see")){
			$json['warn'] = "您没有查看开发文档的权限";
		}else{
			$json = $this->home(array("type" => "内部管理","classify" => "开发文档"));
		}
		//返回
		return $json;
	}
	/*帮助中心*/
	public function adHelp(){
		if(!$this->power("adHelp","see")){
			$json['warn'] = "您没有查看帮助中心的权限";
		}else{
			$json = $this->home(array("type" => "内部管理","classify" => "帮助中心"));
		}
		//返回
		return $json;
	}
	/*列表页
	$data = array(
		"type" => "一级分类",
		"classify" => "二级分类",
	);
	*/
	public function home($data){
		//like查询数组
		$like = array(
			"title" => $this->post['title'],//标题
		);
		//获取查询结果
		$and = " and type = '$data[type]' and classify = '$data[classify]' and xian = '显示'";
		$where = search(array("like" => $like)).$and;
		$page = $this->page(array("table" => "content","where" => $where,"order" => "list"));
		//数据分析
		$json['article'] = array();
		foreach($page['array'] as $array){
			//第一段文字
			$article = query("article","type = '文章管理' and typeId = '$array[id]' and word != '' order by list ");
			if(empty($article['word'])){
				$word = "无文字内容";
			}else{
				$txt = $this->zishu($article['word'],200);
				$replace[1] = "/【【/";
				$replace[2] = "/】】/";
				$replace[3] = "/《《/";
				$replace[4] = "/》》/";
				$class[1] = "【";
				$class[2] = "】";
				$class[3] = "《";
				$class[4] = "》";
				$word = preg_replace($replace,$class,$txt);
			}
			//返回
			$json['article'][] = array(
				"id" => $array['id'],//文章ID
				"title" => $array['title'],//标题
				"clickRate" => $array['clickRate'],//浏览量
				"updateTime" => $array['updateTime'],//更新时间
				"word" => $word,//第一段文字
			);
		}
		$json['warn'] = "success";
		//返回
		$json['page'] = $page['para'];
		return $json;
	}
	/*字数限制*/
	public function zishu($txt,$num){
		if(mb_strlen($txt,'utf8') > $num){
			$dot = "...";
		}else{
			$dot = "";
		}
		$string = mb_substr(html_entity_decode($txt),0,$num,"utf-8").$dot;
		$result = kong($string);
		return $result;
	}
	/*文字转换*/
	public function word($txt){
		$replace[1] = "/\r\n/";
		$replace[2] = "/【【/";
		$replace[3] = "/】】/";
		$replace[4] = "/《《/";
		$replace[5] = "/》》/";
		$class[1] = "</p><p>";
		$class[2] = "<span class='title1'>";
		$class[3] = "</span>";
		$class[4] = "<span class='title2'>";
		$class[5] = "</span>";
		return "<p>".preg_replace($replace,$class,$txt)."</p>";
	}
	/*详情页*/
	public function detail(){
		$content = query("content","id = '".$this->post['id']."'");
		if(empty($this->post['id'])){
			$json['warn'] = "文章ID为空";
		}elseif(empty($content['id'])){
			$json['warn'] = "未找到此文章";
		}else{
			//文章样式
			$json['style'] = array(
				"title1" => "font-size:18px; color:#49a587;",
				"title2" => "color:#49a587;",
				"center" => "text-align:center; max-width:100%;",
			);
			//文章内容
			$article = "";
			$articleSql = find(array("table" => "article","field" => "img,word","where" => "typeId = '$content[id]' order by list"));
			foreach($articleSql['array'] as $array){
				if(empty($array['img'])){
					$article .= $this->word($array['word']);
				}else{
					$article .= "<div class='center'><img src='".root.$array['img']."'></div>";
				}
			}
			//返回
			$json['article'] = array(
				"title" => $content['title'],//文章标题
				"clickRate" => $content['clickRate'],//浏览量
				"updateTime" => $content['updateTime'],//更新时间
				"article" => $article,//文章内容
			);
			$json['warn'] = "success";
		}
		//返回
		return $json;
	}
}
?>